package com.kzc.copygitosc.ui.basefragment;

import android.os.AsyncTask;
import android.os.Bundle;
import android.os.SystemClock;
import android.util.Log;
import android.widget.Toast;

import com.kzc.copygitosc.R;
import com.kzc.copygitosc.adapter.CommonAdapter;
import com.kzc.copygitosc.adapter.TextAdapter;
import com.kzc.copygitosc.bean.Text;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/7/28.
 */
public class TextFragment extends BaseSwipeRefreshFragment<Text>{

    public final static String EXPLORE_TYPE = "explore_type";
    private byte type = 0;

    public static TextFragment newInstance(byte type) {
        TextFragment exploreFeaturedListProjectFragment = new TextFragment();
        Bundle bundle = new Bundle();
        bundle.putByte(EXPLORE_TYPE, type);
        exploreFeaturedListProjectFragment.setArguments(bundle);
        return exploreFeaturedListProjectFragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Bundle args = getArguments();
//        type = args.getByte(EXPLORE_TYPE);

    }

//    @Override
//    public void onViewCreated(View view, Bundle savedInstanceState) {
//        super.onViewCreated(view, savedInstanceState);
//
//
//        loadDataSuccess(getDatas(null));
//    }

    @Override
    public CommonAdapter<Text> getAdapter() {
        return new TextAdapter(getActivity(), R.layout.textitem);
        //return new CommonAdapter(getActivity(), android.R.layout.simple_list_item_1, datas);
    }

    @Override
    public List<Text> getDatas(byte[] responeString) {
        Log.i("xxxx", responeString + "<===");
        List<Text> data = new ArrayList<>();

        long time = SystemClock.currentThreadTimeMillis();

        for (int i=0;i <40;i++){
            data.add(new Text("XXX"+i + "   "+time));
        }

        return data;
    }

    @Override
    public void requestData() {

        new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... params) {
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                return null;
            }

            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                onRequestSuccess(0,null,null);
                onRequestStart();
            }



            @Override
            protected void onPostExecute(Void aVoid) {
                super.onPostExecute(aVoid);
//                loadDataSuccess(getDatas(null));
                onRequestFinish();
            }

        }.execute();


    }

    @Override
    public void onItemClick(int position, Text data) {
        Toast.makeText(getActivity(),"我点击了！"+data.getContent(),Toast.LENGTH_SHORT).show();
    }

}
